<?php
namespace app\api\controller;
use app\common\controller\BaseApi;

/*进出记录api*/
class JpusHelper extends  BaseApi
{
	/**
	 * 测试地址
	 * http://tp5.com/api/JpusHelper/to_list/v/1/t/1/key/zwzl_admin/sign/5de093255ad3e78341dbe00309c9436c
	 * 
	 * $client = new \JPush\Client($app_key, $master_secret);
	 * */
	 public $client='';
	 public function _initialize()
    {
    	//私教打卡设备	
    	//$this->client=new \JPush\Client("194d80f792059f3dfbc7e73b", "442cf1575b99d1c853ba7e6f");
		//tv盒子
    	//$this->client=new \JPush\Client("674e3e1415e04041246c6b11", "a1c8b1a0569946d5ffdc6576");
    }
	/**
	 * http://zwzl.com/api/JpusHelper/test/
	 * */
	public function test(){
		$this->tv(["1ccae33baba1"],1,"http://www.baidu.com");
	}
	/**
	 * http://zwzl.com/api/JpusHelper/test
	 * */
	public function test1(){
		$this->send_notice(["1ccae33baba1"],$v="1.0",$url="http://www.baidu.com");
	}
	//tv 盒子
	public function tv($alias=array(''),$type,$url=""){
		$this->client=new \JPush\Client("674e3e1415e04041246c6b11", "a1c8b1a0569946d5ffdc6576");
		$push_payload = $this->client->push()
		    ->setPlatform(array('ios', 'android'))
			->addAlias($alias)		    
			->message('message content', array(
            'title' => 'tv盒子广告推送',
            'extras' => array(
                'type' => $type,
                'url'=>$url
            ),
        ));
			
		try {
		    $response = $push_payload->send();
			\Think\Log::write($response,"err");
		} catch (\JPush\Exceptions\APIConnectionException $e) {
			\Think\Log::write("推送出错APIConnectionException","err");
		} catch (\JPush\Exceptions\APIRequestException $e) {
			\Think\Log::write("推送出错APIRequestException","err");
		}
	}
	/**
	 * 私教平板 消息推送 
	 * */
	public  function send_notice($alias=array(''),$v="1.0",$url="",$type=1,$title="app更新推送"){
		//私教打卡设备	
    	$this->client=new \JPush\Client("194d80f792059f3dfbc7e73b", "442cf1575b99d1c853ba7e6f");
		$push_payload = $this->client->push()
		    ->setPlatform(array('ios', 'android'))
			->addAlias($alias)		    
			->message('message content', array(
            'title' => $title,
            'extras' => array(
                'type' => $type,
                'url'=>$url,
                'version'=>$v
            ),
        ));
			
		try {
		    $response = $push_payload->send();
			\Think\Log::write($response,"err");
		} catch (\JPush\Exceptions\APIConnectionException $e) {
			\Think\Log::write("推送出错APIConnectionException","err");
		} catch (\JPush\Exceptions\APIRequestException $e) {
			\Think\Log::write("推送出错APIRequestException","err");
		}
	}
	
	/**
	 * 人脸平板 消息推送 
	 * */
	public  function send_face_notice($alias=array(''),$v="1.0",$url="",$type=1,$title="app更新推送"){
		//私教打卡设备	
    	$this->client=new \JPush\Client("9fde2bcdcb44c53b6fca7a19", "a16ca8c89047148ecf98f127");
		$push_payload = $this->client->push()
		    ->setPlatform(array('ios', 'android'))
			->addAlias($alias)		    
			->message('message content', array(
            'title' => $title,
            'extras' => array(
                'type' => $type,
                'url'=>$url,
                'version'=>$v
            ),
        ));
			
		try {
		    $response = $push_payload->send();
			\Think\Log::write($response,"err");
		} catch (\JPush\Exceptions\APIConnectionException $e) {
			\Think\Log::write("推送出错APIConnectionException","err");
		} catch (\JPush\Exceptions\APIRequestException $e) {
			\Think\Log::write("推送出错APIRequestException","err");
		}
	}	
	public function send_face_notice_test(){
		$this->send_face_notice(array("1ccae33ba811"),"","4_2018_8_21_102811_2222233333.jpg",20,"测试图片重传推送");
		var_dump("成功");
	}
////////////////////////////////////////////////////////////////////////////////////
}
